#ifndef FRAMELESSWINDOW_H
#define FRAMELESSWINDOW_H

#include <QWidget>
#include <QPoint>
#include <QVector>
#include <QMouseEvent>

enum Location {
    TOP,
    BOTTOM,
    LEFT,
    RIGHT,
    TOP_LEFT,
    TOP_RIGHT,
    BOTTOM_LEFT,
    BOTTOM_RIGHT,
    CENTER,
};

class FramelessWindow : public QWidget
{
    Q_OBJECT
public:
    explicit FramelessWindow(QWidget* parent = nullptr);
    void setTitleBarWidget(const QVector<QWidget*>& titleBarWidget);

signals:

protected:
    void mousePressEvent(QMouseEvent* event) override;
    void mouseMoveEvent(QMouseEvent* event) override;
    void mouseReleaseEvent(QMouseEvent* event) override;
    bool eventFilter(QObject* watched, QEvent* event) override;
    void mouseDoubleClickEvent(QMouseEvent* event) override;
    void setOnlyMoveByTitlebar(bool b);
    void setResizeable(bool b);
    bool getResizeable() const;

private:
    void setCursorShape(const QPoint& point);
    void setAllWidgetMouseTracking(QWidget* widget);

    bool _leftPressed { false };
    bool _leftPressInTitle { false };
    QPoint _windowPos;
    QPoint _pressPos;
    QVector<QWidget*> _titleBarWidget;
    Location _location { CENTER };
    int _padding { 5 };
    bool _onlyMoveByTitleBar { true };
    bool _resizeable { true };
};

#endif // FRAMELESSWINDOW_H
